﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Xml.Serialization;

namespace Acando.Dynamics.CRM.Silverlight.Library.CrmSdk
{

    public partial class CrmDateTime
    {
        [XmlIgnore]
        public DateTime DateValue
        {
            get { return DateTime.Parse(this.valueField); }
            set
            {
                this.dateField = value.ToShortDateString();
                this.timeField = value.ToShortTimeString();
                TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset(value);
                string sOffset = string.Empty;
                if (offset.Hours < 0)
                {
                    sOffset = "-" + (offset.Hours * -1).ToString().PadLeft(2, '0');
                }
                else
                {
                    sOffset = "+" + offset.Hours.ToString().PadLeft(2, '0');
                }
                sOffset += offset.Minutes.ToString().PadLeft(2, '0');
                this.valueField = value.ToString(string.Format("yyyy-MM-ddTHH:mm:ss{0}", sOffset));
            }
        }
    }
}
